<template>
  <div class="app-container">
    <el-button-group style="float: right;padding-bottom: 5px;">
      <el-button type="dark" icon="el-icon-edit" @click="openNewForm()" plain>新增</el-button>
    </el-button-group>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
      >
      <el-table-column prop="date" label="日期" align="center">
        <template slot-scope="scope">
          {{ scope.row.date }}
        </template>
      </el-table-column>
      <el-table-column label="机构部门" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.orgName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.typeName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="开销" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.value }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" fixed="right">
        <template slot-scope="scope">
          <el-button type="text" @click="openEditForm(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.page"
      :page-sizes="[10, 15, 30, 50]"
      :page-size="pageInfo.limit"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total">
    </el-pagination>
    <data-form :drawer="openDrawer" :orgTypeReport="orgTypeReport" @close="close"/>
  </div>
</template>

<script>
import {getList, getChildrenByDate} from '@/api/orgTypeData'
import dataForm from './dataForm'

export default {
  components:{
    dataForm,
  },
  filters: {},
  data() {
    return {
      list: null,
      listLoading: true,
      openDrawer: false,
      orgTypeReport: {},
      pageInfo: {
        page: 1,
        limit: 10,
        total: 0
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      getList(this.pageInfo).then(response => {
        this.list = response.data.list
        this.pageInfo.total = response.data.total
        this.listLoading = false
      }).catch(()=>{alert("err")})
    },
    openNewForm() {
      this.openDrawer = true
    },
    openEditForm(value) {
      this.orgTypeReport = value
      this.openDrawer = true
    },
    close(v) {
      this.openDrawer = v
      this.orgTypeReport = {}
    },
    handleSizeChange(val) {
      this.pageInfo.limit = val
      this.pageInfo.page = 1
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.pageInfo.page = val
      this.fetchData()
    }
  }
}
</script>
